#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
void calc_ma_null(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
}

void calc_ma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdClose=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	for(i=0;i<pFormula->numLine;++i)
	{
		memcpy(dataCalc[i],pcdClose,numCalc*sizeof(double));
		UMyCalc_MA(dataCalc[i],numCalc,pFormula->infoParam[i].nowValue);
	}
}

void calc_hma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdHigh=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdHigh[i] = paData[i].highPx/seedPrice;

	for(i=0;i<pFormula->numLine;++i)
	{
		memcpy(dataCalc[i],pcdHigh,numCalc*sizeof(double));
		UMyCalc_MA(dataCalc[i],numCalc,pFormula->infoParam[i].nowValue);
	}
}

void calc_lma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdLow=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdLow[i] = paData[i].lowPx/seedPrice;

	for(i=0;i<pFormula->numLine;++i)
	{
		memcpy(dataCalc[i],pcdLow,numCalc*sizeof(double));
		UMyCalc_MA(dataCalc[i],numCalc,pFormula->infoParam[i].nowValue);
	}
}

void calc_vma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdMiddle=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdMiddle[i] = (paData[i].highPx+paData[i].lowPx+paData[i].openPx+paData[i].ClosePx)/seedPrice/4;

	for(i=0;i<pFormula->numLine;++i)
	{
		memcpy(dataCalc[i],pcdMiddle,numCalc*sizeof(double));
		UMyCalc_MA(dataCalc[i],numCalc,pFormula->infoParam[i].nowValue);
	}
}

void calc_expma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdClose=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	for(i=0;i<pFormula->numLine;++i)
	{
		UMyCalc_EXPMA(dataCalc[i],pcdClose,numCalc,pFormula->infoParam[i].nowValue);
	}
}

void calc_dma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	double*fpMA1=dataCalc[4],*fpMA2=dataCalc[5];
	double*DIF=dataCalc[0],*DMAMA=dataCalc[1];

	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdClose=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	memcpy(fpMA1,pcdClose,numCalc*sizeof(double));
	memcpy(fpMA2,pcdClose,numCalc*sizeof(double));

	UMyCalc_MA(fpMA1,numCalc,pFormula->infoParam[0].nowValue);
	UMyCalc_MA(fpMA2,numCalc,pFormula->infoParam[1].nowValue);
	UMyCalc_SUB(DIF,fpMA1,fpMA2,numCalc);

	memcpy(DMAMA,DIF,numCalc*sizeof(double));
	UMyCalc_MA(DMAMA,numCalc,pFormula->infoParam[2].nowValue);
}
/*
	DIF:MA(CLOSE,N1)-MA(CLOSE,N2);
	AMA:MA(DIF,M);
*/

void calc_mfma(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double*pcdMoneyflow=dataCalc[9];

	for(i=0;i<numCalc;++i)
		pcdMoneyflow[i] = (double)paData[i].MONEY_FLOW;

	for(i=0;i<pFormula->numLine;++i)
	{
		memcpy(dataCalc[i],pcdMoneyflow,numCalc*sizeof(double));
		UMyCalc_MA(dataCalc[i],numCalc,pFormula->infoParam[i].nowValue);
	}

}